# compiler and flags
CXX:=gpp
CXXFLAGS:=-I ./include -nostdlib -fno-rtti -fno-exceptions
## DJGPP ELF-ENABLED LD ###
LD:=C:\djgpp\bin\ld-elf
LDFLAGS:=-T linker.ld -Map link.map -o
# assembler
NASM:=nasmw
AS:=as-elf
NASM_SRCS:=$(shell dir /b /s *.s)
AS_SRCS:=$(shell dir /b /s *.asm)
# source and objects, and final binary
SRCS:=$(shell dir /b /s *.cc)
OBJS:=$(patsubst %.asm,%.o,$(AS_SRCS)) $(patsubst %.s,%.o,$(NASM_SRCS)) $(patsubst %.cc,%.o,$(SRCS))
FINALBIN:=kernel.bin

# clean up
clean:
	del $(OBJS) *.bin

# buld the full kernel
all: $(FINALBIN)

# link command
$(FINALBIN) : $(OBJS)
	@echo Linking
	@echo $(OBJS) > objects.txt
	@$(LD) $(LDFLAGS) $(FINALBIN) @objects.txt
	@del comp.txt objects.txt

# C++ source
# -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wredundant-decls -Winline -Wno-long-long -Wconversion
# the above = nightmare!
%.o : %.cc
	@echo Compiling $<
	@echo $(CXXFLAGS) -c $< -o $@ > comp.txt
	@$(CXX) @comp.txt

# assembly
%.o : %.asm irq.inc isr.inc
	@echo Assembling $<
	@$(AS) $< -o $@

%.o: %.s
	@echo Assembling $<
	@$(NASM) -f elf -o $@ $<
